import router from "./index";
import store from '@/store'
import nprogress from 'nprogress'
import 'nprogress/nprogress.css'


const whiteURL = ['/login','/404']
router.beforeEach((to,from,next)=>{
  nprogress.start()
  console.log("store.state.user.token",store.state.user.token);
  console.log(to.path);
  if(store.state.user.token != null){
    if(to.path !== '/login'){
      next()
    }
    else{
      next('/')
    }
  }
  else {
    if(whiteURL.includes(to.path)){
      next()
    }
    else{
      next('/login')
    }
  }
})

router.afterEach((to,from)=>{
  nprogress.done()
})
